package com.validator.plus;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ReturnT<T> implements Serializable {

    private static final long serialVersionUID = 4921114729569667431L;
    //状态码，200为成功，其它为失败
    private Integer code;
    //消息提示
    private String message;
    //数据对象
    private T data;
    //成功状态码
    public static final int SUCCESS = 200;
    //失败状态码
    public static final int ERROR = 1000;

    public static <R> ReturnT<R> success(R data) {
        return new ReturnT<>(SUCCESS, "SUCCESS", data);
    }
    public static <R> ReturnT<R> error(String msg) {
        return new ReturnT<>(ERROR, msg, null);
    }
}
